<div>
<div class="layui-fluid">
  <div class="layui-row">
    <div class="layui-col-xs12">
      <div class="layui-card">
        <div class="layui-card-header">添加站内新闻信息</div>
        <div class="layui-card-div newsAdd ">
          
   
			<form class="layui-form">
			  <div class="layui-form-item">
			    <label class="layui-form-label">新闻名称</label>
			    <div class="layui-input-block">
			      <input type="text" name="title" lay-verify="title" autocomplete="off"  class="layui-input">
			    </div>
			  </div>
			  
			  <div class="layui-form-item">
			    <label class="layui-form-label">内容</label>
			    <div class="layui-input-block">
			      	
			      	<textarea id="demo" style="display: none;"></textarea>
			        <script>
			        	var layeditRef,layeditIndex;
						layui.use('layedit', function(){
						  layeditRef = layui.layedit;
						  layeditIndex = layeditRef.build('demo',{
							  tool: [
							         'strong' //加粗
							         ,'italic' //斜体
							         ,'underline' //下划线
							         ,'del' //删除线
							         ,'|' //分割线
							         ,'left' //左对齐
							         ,'center' //居中对齐
							         ,'right' //右对齐
							         ,'link' //超链接
							         ,'unlink' //清除链接
							       ]
						  }); //建立编辑器
						});
					 </script>
			    </div>
			  </div>
			  <div class="layui-form-item">
			    <label class="layui-form-label">作者</label>
			    <div class="layui-input-block">
			      <input type="text" name="author" lay-verify="title" autocomplete="off"  class="layui-input">
			    </div>
			  </div>
			  
			  <div style="color:red;text-align:center;">{{errMsg}}</div>
			  
			  <div class="layui-form-item">
					<div class="layui-input-block" style="text-align:center;">
				       <button type="button" class="layui-btn" v-on:click="ajaxSubmit">提交</button>
          			</div>
			  </div>
			  
			</form>	 
			
			      
			    <div style="color:red;text-align:center;">{{errMsg2}}</div>
			 </div>
				 
				
			      
			      
			      <script src="/lay/modules/laydate.js"></script>
			      <script>
				      	/* layui.use('form', function(){
					  		
					  	});
					  	var laydate = layui.laydate;
					  	
					  	laydate.render({
					  	    elem: '#publishdateComponent2' //指定元素
					  	  	,done: function(value, date){ //监听日期被切换
						  	  	window.publishdateComponentValue = value;
						  	  }
					  	  }); */
			      </script>
			</div>
				  
         
        </div>
      </div>
    </div>
  </div>
</div>

</div>
<!-- 脚本 -->
<script src="/lay/modules/laydate.js"></script>

<script>

	var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
	
	var newsAdd = new Vue({
		el : '.newsAdd' ,
		data : {
			
			errMsg : '',
			errMsg2 : '',
			dataSource : [{
				
			}]
		} ,
		
		methods: {
			
			//数据加载
			loadData : function(){
				
				window.id = layui.router().search.id;
				if(!id){
					return;
				}
				$.post("/news/getById.do",{id:id},function(data){
					
					$("input[name='title']").val(data.title);
					$("input[name='author']").val(data.author);
					setTimeout(function(){
						layeditRef.setContent(layeditIndex,data.content,false);
					},100);
					
					
				},'json');
				
			} ,
			
			ajaxSubmit : function (){
				var obj = {}
				 if(!$("input[name='title']").val()){
					 this.errMsg = '站内新闻名称不允许为空！';
					 return;
				 }else{
					 obj.title = $("input[name='title']").val();
				 }
				
				obj.author = $("input[name='author']").val();
				
				obj.id = window.id;
				
				obj.content = layeditRef.getContent(layeditIndex);
				
				$.post("/news/add.do",obj,function(data){
					if(data.code != 0){
						alert("后台出现错误，请核实！");
						return;
					}
					alert('保存成功！');
					location.href="/#/news/query";
				},'json');
				
			}
			
		}
	});
	
	newsAdd.loadData();
	
	//必须要写， 不然select显示不出来！
	layui.use('form', function(){
		
	});
	var laydate = layui.laydate;
	
	layui.use('form', function(){
        var form = layui.form; 
        form.render();
 }); 
	
	
  
</script>
<!-- 样式 -->
<style scoped>

</style>



